package com.ztools.mvp.proxy.impl;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.ztools.mvp.IPresenter;
import com.ztools.mvp.IView;
import com.ztools.mvp.proxy.FragmentLifecycleCallback;
import com.ztools.mvp.proxy.MvpBindCallback;


/**
 * 管理Activity的生命周期
 * Created by zhangxuehui on 2018/3/13.
 */

public class FragmentLifecycleCallbackProxy<V extends IView, P extends IPresenter<V>> implements FragmentLifecycleCallback<V, P> {

    private MvpBindCallback<V, P> mTargetCallback;
    private MvpBindCallbackProxy<V, P> mTargetCallbackProxy;

    public FragmentLifecycleCallbackProxy(MvpBindCallback<V, P> mTargetCallback) {
        this.mTargetCallback = mTargetCallback;
    }

    public MvpBindCallbackProxy<V, P> getMvpBindCallbackProxy() {
        if (this.mTargetCallback != null) {
            this.mTargetCallbackProxy = new MvpBindCallbackProxy<>(this.mTargetCallback);
        }
        return this.mTargetCallbackProxy;
    }

    @Override
    public void onAttach() {
        IPresenter presenter = getMvpBindCallbackProxy().newPresenter();
        if (presenter == null) {
            LogUtils.e("MVP presenter is NULL");
        }
        IView view = getMvpBindCallbackProxy().newMvpView();
        if (view == null) {
            LogUtils.e("MVP view is NULL");
        }
        getMvpBindCallbackProxy().attachView();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onResume() {
    }

    @Override
    public void onStop() {

    }

    @Override
    public void onDetach() {
        getMvpBindCallbackProxy().detachView();
    }

    @Override
    public void onDestroyView() {
    }

    @Override
    public void onDestroy() {
    }
}
